interface RequestInterface {
	method:
		| 'OPTIONS'
		| 'GET'
		| 'HEAD'
		| 'POST'
		| 'PUT'
		| 'DELETE'
		| 'TRACE'
		| 'CONNECT';
	data?: {};
}

const baseUrl: string =
	'https://netease-cloud-music-api-crete722p-hannah-bingo.vercel.app';

export function request(url: string, data: RequestInterface) {
	uni.showLoading({
		title: '加载中...',
	});
	return new Promise((resolve, reject) => {
		uni.request({
			url: baseUrl + url,
			method: data.method,
			data: data.data,
			success: (result) => {
				resolve(result.data);
			},
			fail(error) {
				reject(error.errMsg);
			},
			complete() {
				uni.hideLoading();
			},
		});
	});
}
